package Array;

import org.junit.Test;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: Array
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-10-18  16:41
 * @Description: TODO
 * @Version: 1.0
 */
public class 买卖股票的最佳时机121 {

    public int maxProfit(int[] prices) {
        int max = 0;
        int min = prices[0];
        for (int i = 1; i < prices.length; i++) {
            min = Math.min(prices[i], min);
            max = Math.max(max, (prices[i] - min));
        }
        return max;
    }

    @Test
    public void tets(){
        int i = maxProfit(new int[]{7,6,4,3,1});
        System.out.println(i);
    }
}
